package com.example.travelround.mymusic.main;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.example.travelround.mymusic.R;
import com.example.travelround.mymusic.base.BaseFragment;
import com.example.travelround.mymusic.main.live.LiveFragment;
import com.example.travelround.mymusic.main.mine.MineFragment;
import com.example.travelround.mymusic.main.music.MusicFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by travelround on 17/3/8.
 */

public class MainFragment extends BaseFragment {

    private ViewPager viewPager;
    private TabLayout tabLayout;

    @Override
    public int setLayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void initView(View view) {
        viewPager = byView(R.id.main_vp);
        tabLayout = byView(R.id.main_tab);
        // viewPager = (ViewPager) view.findViewById(R.id.main_vp);
        // tabLayout = (TabLayout) view.findViewById(R.id.main_tab);
    }

    @Override
    public void initData() {
        MainViewPagerAdapter adapter = new MainViewPagerAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);


        List<Fragment> fragments = new ArrayList<>();
        MineFragment mineFragment = new MineFragment();
        MusicFragment musicFragment = new MusicFragment();
        LiveFragment liveFragment = new LiveFragment();
        fragments.add(mineFragment);
        fragments.add(musicFragment);
        fragments.add(liveFragment);
        adapter.setFragments(fragments);

        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(0).setText("我的");
        tabLayout.getTabAt(1).setText("音乐");
        tabLayout.getTabAt(2).setText("活动");
    }

}
